﻿

var submit = function () {
    if ($('form .validate').length) return false;
    $.prompt("Do you want to save the feedback?", {
        title: "Confirm",
        buttons: { "Yes": true, "Cancel": false },
        submit: function (e, v) {
            // use e.preventDefault() to prevent closing when needed or return false. 
            // e.preventDefault(); 
            if (!v) return;
//            if ($('#from-date').val() == '') {
//                $('#from-date').parent().append('<label class="validate" style="color: red" title="Start date is not null.">*</label>');
//                return;
//            }
//            if ($('#to-date').val() == '') {
//                $('#to-date').parent().append('<label class="validate" style="color: red" title="End date is not null.">*</label>');
//                return;
//            }

            $.ajax({
                type: "POST",
                url: "/Pages/Feedback.aspx/SaveFeedback",
                data: JSON.stringify({
                    feedback: {
                        Subject: $('#Subject').val(),
                        Comment: $('#usersComment').val()
                    }
                }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success: function (data) {
                    if (data.d) {
                        $.prompt('You have saved successfully.');
                        window.location.href = '/Pages/Feedback.aspx';
                    }
                },
                error: function () {
                }
            });
        }
    });

    return false;
};

var reset = function () {

    $('#Subject').val('');
    $('#usersComment').val('');
    return false;
};


$(document).ready(function () {
//    var today = new Date();
    $('#submit').click(submit);
    $('#reset').click(reset);
});